import { Component, OnInit } from '@angular/core';
import { Singlepage } from '../../model/singlepage';
import { HttpClient } from '@angular/common/http';
import { ActivatedRoute, Router } from '@angular/router';
import { SinglepageService } from '../../service/singlepage.service';

@Component({
  selector: 'app-uploadsinglepage',
  templateUrl: './uploadsinglepage.component.html',
  styleUrls: ['./uploadsinglepage.component.css']
})
export class UploadsinglepageComponent implements OnInit {
  sl:Array<Singlepage>;
  constructor(private http:HttpClient,
    private routerinfo:ActivatedRoute,
    private router:Router,
    private singlepageservice:SinglepageService
    ) {
      this.sl=new Array();
     }

  ngOnInit() {
    this.loadSinglepagelist();
  }

  private loadSinglepagelist(){
    this.sl=new Array();
    this.singlepageservice.getSinglepageList()
    .then((data:any)=>{
      this.sl=data;
  
    })
  
  }

  addSinglepage(){
    this.router.navigate(['editsinglepage','add']);
  }

  updateSinglepage(id:string){
    this.router.navigate(['editsinglepage',id]);
  }

  deleteSinglepage(id:string){
    this.singlepageservice.deleteSinglepage(id)
    .then((flag:boolean)=>{
      if(flag==true){
        this.loadSinglepagelist();
      }else{
        alert("删除异常，请刷新后重试")
      }
    })
  }

}
